package com.zzw.tddl;

import java.text.MessageFormat;

/**
 * 描述
 *
 * @author zhulixin
 */
public class AucsRuleMain {

    public static void main(String[] args) throws Exception {
        System.setProperty("nacos.endpoint", "midenv.to7.mychebao.com");
        //ConfigService configService = NacosFactory.createConfigService();
        String app = "aucsmto7";
        String tableCount = "4";
        String tableSingleDb = "2";

        // 插入版本号
        String dataId = new MessageFormat("com.taobao.tddl.rule.le.{0}.versions").format(new Object[]{app});
        String version = "V1";
       /* boolean result = configService.publishConfig(dataId, null, "V1");
        System.out.println(result);*/
        System.out.println(dataId);
        System.out.println("V1");

        // 插入规则
        dataId = new MessageFormat("com.taobao.tddl.rule.le.{0}.{1}").format(new Object[]{app, version});
        String content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                "<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">\n" +
                "<beans>\n" +
                "    <bean id=\"vtabroot\" class=\"com.taobao.tddl.rule.VirtualTableRoot\" init-method=\"init\">\n" +
                "        <property name=\"dbType\" value=\"MYSQL\" />\n" +
                "        <property name=\"lazyInit\" value=\"true\" />\n" +
                "        <property name=\"defaultDbIndex\" value=\"" + app + "_main\"/>\n" +
                "        <property name=\"tableRules\">\n" +
                "            <map>\n" +
                "                <entry key=\"ams_bidprice_virtual\" value-ref=\"ams_bidprice_virtual\" />\n" +
                "            </map>\n" +
                "        </property>\n" +
                "    </bean>\n" +
                "\n" +
                "    <bean id=\"ams_bidprice_virtual\" class=\"com.taobao.tddl.rule.TableRule\">\n" +
                "        <property name=\"allowFullTableScan\" value=\"true\" />\n" +
                "        <property name=\"dbNamePattern\" value=\"" + app + "_group{0}\" />\n" +
                "        <property name=\"dbRuleArray\">\n" +
                "            <value>Math.abs(Long.valueOf(#auctionCarId,1," + tableCount + "#) %" + tableCount + ").intdiv(" + tableSingleDb + ")</value>\n" +
                "        </property>\n" +
                "        <property name=\"tbRules\" value=\"Math.abs(Long.valueOf(#auctionCarId,1," + tableCount + "#)) % " + tableCount + "\" />\n" +
                "        <property name=\"tbNamePattern\" value=\"ams_bidprice_virtual_{0000}\" />\n" +
                "    </bean>\n" +
                "</beans>";
       /* result = configService.publishConfig(dataId, null, content);
        System.out.println(result);*/
        System.out.println(dataId);
        System.out.println(content);

    }
}
